<template>
	<view class="content">
		<u-search placeholder="请输入设备名称搜索" v-model="queryForm.keyword" :show-action="false" bg-color="#FFFFFF"
			color="#999999" height="80" @search="list = [],queryForm.pageNum = 1,getPage()"></u-search>
		<u-gap height="32" bg-color="#F5F7FA"></u-gap>
		<u-empty v-if="list.length == 0" mode="list" style="margin-top: 300rpx;"></u-empty>
		<view class="wait-item" v-for="(item, index) in list" :key="index">
			<view class="wait-item-top">
				<view class="wait-item-top-name">
					{{item.eqName}}
				</view>
				<view class="wait-item-top-code">
					{{item.eqCode}}
				</view>
			</view>
			<view class="wait-item-location">
				设备位置：{{item.eqPosition}}
			</view>
			<view class="wait-item-location">
				维保人：{{item.maintenancePersonStr}}
			</view>
			<view class="wait-item-time">
				维保时间：{{item.maintenanceTime}}
			</view>
			<view class="wait-item-bottom">
				<view class="wait-item-bottom-status" :style="{color:statusColorList[item.state]}">
					{{statusList[item.state]}}
				</view>
				<view class="wait-item-bottom-btn">
					<u-button type="primary" plain shape="circle" :custom-style="customStyle"
						@click="toDetail(item)">详情</u-button>
					<u-button v-if="item.state == 0" type="primary" plain shape="circle" :custom-style="customStyle"
						@click="toRepair(item)">维保</u-button>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				queryForm: {
					keyword: '',
					state: [0, 2],
					pageNum: 1,
					pageSize: 20
				},
				list: [],
				statusList: ['待维保', '', '已完成'],
				statusColorList: ['#999999', '', '#06A573'],
				customStyle: {
					height: '54rpx',
					marginLeft: '15rpx',
				}
			}
		},
		// onLoad() {
		// 	this.getPage()
		// },
		onShow() {
			this.list = []
			this.queryForm.pageNum = 1
			this.getPage()
		},
		onReachBottom() {
			if (this.total > this.queryForm.pageSize * this.queryForm.pageNum) {
				this.queryForm.pageNum++
				this.getPage()
			}
		},
		onPullDownRefresh() {
			this.list = []
			this.queryForm.pageNum = 1
			this.getPage()
			uni.stopPullDownRefresh()
		},
		methods: {
			getPage() {
				this.$u.api.maintenanceQuery(this.queryForm).then(res => {
					this.list = this.list.concat(res.rows)
					this.total = res.recordCount
				})
			},
			toDetail(item) {
				uni.navigateTo({
					url: '/pages/repair/detail?id=' + item.id
				})
			},
			toRepair(item) {
				uni.navigateTo({
					url: '/pages/repair/repair?id=' + item.id + '&equipmentId=' + item.equipmentId
				})
			}
		}
	}
</script>
<style>
	page {
		background-color: #F5F7FA;
	}
</style>
<style lang="scss" scoped>
	.content {
		padding: 32rpx 28rpx;

		.wait-item {
			width: 694rpx;
			background: #FFFFFF;
			border-radius: 16rpx;
			margin-bottom: 28rpx;
			padding: 33rpx 32rpx 28rpx 37rpx;

			.wait-item-top {
				display: flex;
				align-items: center;

				.wait-item-top-name {
					font-weight: 600;
					font-size: 36rpx;
					color: #333333;
					line-height: 50rpx;
					margin-right: 20rpx;
				}

				.wait-item-top-code {
					line-height: 40rpx;
					border-radius: 6rpx;
					border: 1rpx solid #3068E7;
					font-weight: 400;
					font-size: 26rpx;
					color: #3068E7;
					text-align: center;
					padding: 0 12rpx;
				}
			}

			.wait-item-location {
				font-weight: 400;
				font-size: 26rpx;
				color: #999999;
				line-height: 37rpx;
				margin-top: 20rpx;
			}

			.wait-item-time {
				font-weight: 400;
				font-size: 26rpx;
				color: #999999;
				line-height: 37rpx;
				margin-top: 14rpx;
				margin-bottom: 28rpx;
			}

			.wait-item-bottom {
				display: flex;
				align-items: center;
				justify-content: space-between;
				padding-top: 28rpx;
				border-top: 1rpx solid #E6E6E6;

				.wait-item-bottom-status {
					font-weight: 400;
					font-size: 26rpx;
					color: #FEA03D;
					line-height: 37rpx;
				}

				.wait-item-bottom-btn {
					display: flex;
				}
			}


		}
	}
</style>